package com.training.killerapp;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.training.killerapp.model.User;

public class ListServlet extends AbstractKillerAppServlet
{
    protected void doGet( HttpServletRequest request, HttpServletResponse response )
        throws ServletException, IOException
    {
        User currentUser = getCurrentUser( request );

        KillerApp killerApp = retrieveKillerApp();
        try
        {
            request.setAttribute( "currentUserEmail", currentUser.getEmail() );
            request.setAttribute( "users", killerApp.getUserIterator() );

            RequestDispatcher dispatcher = request.getRequestDispatcher( "list.jsp" );
            dispatcher.forward( request, response );
        }
        finally
        {
            releaseKillerApp( killerApp );
        }
    }
}
